
package tests.laurens.cajo;

import gnu.cajo.Cajo;

import java.rmi.RemoteException;


interface SuperSet { // client method sets need not be public
	void baz() throws RemoteException;
} // declaring RemoteException is optional, but a nice reminder


interface ClientSet extends SuperSet {
	boolean bar(Integer quantum) throws RemoteException;
	Object foo(String barbaz, int foobar) throws RemoteException;
} // the order of the client method set does not matter


public class Client {
	public static void main(String args[]) throws Exception { // unit test
		Cajo cajo = new Cajo(0, "", "");
		if(args.length > 0) { // either approach must work...
			int port = args.length > 1 ? Integer.parseInt(args[1]) : 1198;
			cajo.register(args[0], port);
			// find server by registry address & port, or...
		} else Thread.currentThread().sleep(100); // allow some discovery time

		Object refs[] = cajo.lookup(ClientSet.class);
		if(refs.length > 0) { // compatible server objects found
			System.out.println("Found " + refs.length);
			ClientSet cs = (ClientSet) cajo.proxy(refs[0], ClientSet.class);
			cs.baz();
			System.out.println(cs.bar(new Integer(77)));
			System.out.println(cs.foo(null, 99));
		} else System.out.println("No server objects found");
		System.exit(0); // nothing else left to do, so we can shut down
	}
}
